var t = require;
var e = module;
var o = exports;
var i, n = this && this.__extends || (i = function(t, e) {
    return (i = Object.setPrototypeOf || {
        __proto__: []
    }
    instanceof Array &&
    function(t, e) {
        t.__proto__ = e
    } ||
    function(t, e) {
        for (var o in e) Object.prototype.hasOwnProperty.call(e, o) && (t[o] = e[o])
    })(t, e)
},
function(t, e) {
    function o() {
        this.constructor = t
    }
    i(t, e),
    t.prototype = null === e ? Object.create(e) : (o.prototype = e.prototype, new o)
}),
a = this && this.__decorate ||
function(t, e, o, i) {
    var n, a = arguments.length,
    r = a < 3 ? e: null === i ? i = Object.getOwnPropertyDescriptor(e, o) : i;
    if ("object" == typeof Reflect && "function" == typeof Reflect.decorate) r = Reflect.decorate(t, e, o, i);
    else for (var s = t.length - 1; s >= 0; s--)(n = t[s]) && (r = (a < 3 ? n(r) : a > 3 ? n(e, o, r) : n(e, o)) || r);
    return a > 3 && r && Object.defineProperty(e, o, r),
    r
};
Object.defineProperty(o, "__esModule", {
    value: !0
});
var r = t("GlobalUserData"),
s = t("GameConstant"),
l = t("GoldFlyAnim"),
c = t("ConfirmRewardPanel"),
d = t("BroadCastMessage"),
h = t("Util"),
p = cc._decorator,
u = p.ccclass,
f = p.property,
m = function(t) {
    function e() {
        var e = null !== t && t.apply(this, arguments) || this;
        return e.pfb_FlyGold = null,
        e.node_iconGold = null,
        e.node_btnClick = null,
        e.reward_icon_list = null,
        e.progressAward = null,
        e.progressTime = null,
        e.node_car = null,
        e.lab_time = null,
        e.lab_gold1 = null,
        e.lab_gold2 = null,
        e.lab_gold3 = null,
        e.lab_gold4 = null,
        e.lab_gold5 = null,
        e.node_light = null,
        e.awardGoldList = [100, 300, 500, 1e3, 2e3],
        e.nCurTime = 0,
        e.nMaxTime = 5,
        e.SpeedSub = .04,
        e.progress = 0,
        e.bStart = !1,
        e.getAwardIndex = 0,
        e._closeCB = null,
        e.nStartTime = 0,
        e.chance_mistake_touch = [{
            min: .2 - .05,
            max: .4 - .05
        },
        {
            min: .2 - .05,
            max: .4 - .05
        },
        {
            min: .2 - .05,
            max: .4 - .05
        },
        {
            min: .36,
            max: .6 - .05
        },
        {
            min: .36,
            max: .6 - .05
        },
        {
            min: .36,
            max: .6 - .05
        },
        {
            min: .36,
            max: .6 - .05
        },
        {
            min: .36,
            max: .6 - .05
        },
        {
            min: .61 - .05,
            max: .75
        },
        {
            min: .76,
            max: .85
        }],
        e.bShowBanner = !1,
        e
    }
    return n(e, t),
    e.prototype.start = function() {
        h.Util.event_dispatcher.register(this),
        cc.resources.load("prefab/confirmRewardPanel"),
        h.Util.hideBanner()
    },
    e.prototype.onDestroy = function() {
        h.Util.event_dispatcher.remove(this),
        r.default.isGiftRushShow = !1
    },
    e.prototype.initView = function(t) {
        r.default.isGiftRushShow = !0,
        this._closeCB = t,
        this.lab_gold1.string = h.Util.transformGoldStr(this.awardGoldList[0]),
        this.lab_gold2.string = h.Util.transformGoldStr(this.awardGoldList[1]),
        this.lab_gold3.string = h.Util.transformGoldStr(this.awardGoldList[2]),
        this.lab_gold4.string = h.Util.transformGoldStr(this.awardGoldList[3]),
        this.lab_gold5.string = h.Util.transformGoldStr(this.awardGoldList[4]),
        this.progressAward.progress = 0,
        this.progressTime.progress = 0,
        this.progress = 0,
        this.onPosCar(this.progress),
        this.nCurTime = 0,
        this.lab_time.string = (this.nMaxTime - this.nCurTime).toString(),
        this.bStart = !1,
        cc.tween(this.node_light).by(3, {
            angle: 360
        }).repeatForever().start()
    },
    e.prototype.onBtnSpeedClick = function() {
        this.bStart || this.onCountDown(),
        this.progress += this.SpeedSub,
        this.progress > .9 && (this.progress = .9),
        this.progressAward.progress = this.progress,
        this.onPosCar(this.progress),
        this.onShowBanner();
        for (var t = this.awardGoldList.length; t > 0; t--) if (this.progress > t / 6) {
            this.getAwardIndex = t;
            for (var e = 1; e <= t; e++) {
                var o = this.reward_icon_list.children[t].getChildByName("mask");
                o && (o.active = !1)
            }
            return
        }
    },
    e.prototype.onPosCar = function() {
        this.node_car.x = 950 * (this.progress - .5)
    },
    e.prototype.onClose = function() {
        h.Util.hideBanner(),
        this._closeCB && this._closeCB(),
        this.node && this.node.destroy(),
        this.unscheduleAllCallbacks()
    },
    e.prototype.onCountDown = function() {
        var t = this;
        this.node_btnClick.active = !0,
        this.bStart = !0,
        this.schedule(function() {
            t.nMaxTime == t.nCurTime ? (t.node_btnClick.active = !1, t.playGetGoldAnim(), t.unscheduleAllCallbacks()) : (t.nCurTime++, t.lab_time.string = (t.nMaxTime - t.nCurTime).toString())
        },
        1)
    },
    e.prototype.onWxShow = function() {
        this.onWxNavigateBack()
    },
    e.prototype.onWxNavigateBack = function() {
        this.onPosCar(0),
        this.unscheduleAllCallbacks(),
        this.lab_time.string = "0",
        this.node_btnClick.active = !1,
        h.Util.hideBanner(),
        this.playGetGoldAnim(!1)
    },
    e.prototype.update = function(t) {
        this.bStart && (this.nStartTime += t, this.progressTime.progress = 1 - this.nStartTime / this.nMaxTime),
        this.progress > 0 && this.onDownSpeed(),
        this.progress < 0 && (this.progress = 0),
        this.progressAward.progress = this.progress,
        this.onPosCar(this.progress)
    },
    e.prototype.onDownSpeed = function() {
        this.progress <= .1 ? this.progress -= .013 * this.SpeedSub: this.progress <= .2 ? this.progress -= .0192 * this.SpeedSub: this.progress <= .3 ? this.progress -= .0224 * this.SpeedSub: this.progress <= .4 ? this.progress -= 1.8 * .016 * this.SpeedSub: this.progress <= .5 ? this.progress -= .04 * this.SpeedSub: this.progress <= .6 ? this.progress -= .048 * this.SpeedSub: this.progress <= .7 ? this.progress -= .0512 * this.SpeedSub: this.progress <= .8 ? this.progress -= .056 * this.SpeedSub: this.progress -= .064 * this.SpeedSub
    },
    e.prototype.onShowBanner = function() {
        if (!this.bShowBanner) {
            var t = h.Util.getRandomInt(0, this.chance_mistake_touch.length),
            e = 100 * this.chance_mistake_touch[t].min,
            o = 100 * this.chance_mistake_touch[t].max,
            i = h.Util.getRandomInt(e, o);
            i /= 100,
            this.progress > i && (this.bShowBanner = !0, r.default.curGiftRushBannerIndex = h.Util.getCurbannerIndex(), h.Util.showBanner(), cc.log("当前急速夺宝banner下标: " + r.default.curGiftRushBannerIndex))
        }
    },
    e.prototype.playGetGoldAnim = function(t) {
        var e = this;
        void 0 === t && (t = !0);
        for (var o = 0,
        i = 0; i < this.getAwardIndex; i++) o += this.awardGoldList[i];
        if (o > 0) {
            r.default.saveGoldData(!0, o);
            var n = cc.instantiate(cc.resources.get("prefab/confirmRewardPanel"));
            cc.find("Canvas").addChild(n, 100),
            n.getComponent(c.default).initView([{
                type: c.rewardType.gold,
                num: o
            }],
            function() {
                t && e.playAudio(s.Game_Audio_ID.get_gold);
                var o = cc.v3(200, cc.winSize.height, 0);
                h.Util.AnimFly(l.Fly_Type.Gold, e.pfb_FlyGold, e.node_iconGold, o,
                function() {},
                function() {
                    e.onClose()
                })
            },
            !1)
        } else this.onClose()
    },
    e.prototype.playAudio = function(t) {
        d.default.getInstance().SendMessage(s.Game_Broadcast_Func.Audio, t)
    },
    a([f(cc.Prefab)], e.prototype, "pfb_FlyGold", void 0),
    a([f(cc.Node)], e.prototype, "node_iconGold", void 0),
    a([f(cc.Node)], e.prototype, "node_btnClick", void 0),
    a([f(cc.Node)], e.prototype, "reward_icon_list", void 0),
    a([f(cc.ProgressBar)], e.prototype, "progressAward", void 0),
    a([f(cc.ProgressBar)], e.prototype, "progressTime", void 0),
    a([f(cc.Node)], e.prototype, "node_car", void 0),
    a([f(cc.Label)], e.prototype, "lab_time", void 0),
    a([f(cc.Label)], e.prototype, "lab_gold1", void 0),
    a([f(cc.Label)], e.prototype, "lab_gold2", void 0),
    a([f(cc.Label)], e.prototype, "lab_gold3", void 0),
    a([f(cc.Label)], e.prototype, "lab_gold4", void 0),
    a([f(cc.Label)], e.prototype, "lab_gold5", void 0),
    a([f(cc.Node)], e.prototype, "node_light", void 0),
    a([u], e)
} (cc.Component);
o.default = m